package org.BUPT.modules.system.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.BUPT.common.enums.StatusEnum;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;



@Data
@Entity
@Table(name="sys_subject")
@EntityListeners(AuditingEntityListener.class)
public class Subject {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long id;


    private String title;
    /** 创建时间 */
    @CreatedDate
    private Date createDate;



    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "sys_subject_user",
            joinColumns = @JoinColumn(name = "subject_id"),
            inverseJoinColumns = @JoinColumn(name = "user_id"))
    @JsonIgnore
    private Set<User> teachers = new HashSet<>(0);

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "sys_subject_user",
            joinColumns = @JoinColumn(name = "subject_id"),
            inverseJoinColumns = @JoinColumn(name = "user_id"))
    private Set<User> students = new HashSet<>(0);

    /** 数据状态 */
    private Byte status = StatusEnum.OK.getCode();
}
